<?php
require('../conn.php');
require('../functions.php');
require('admin.php');
$vid = $_GET['id'];
$videoInfo = $mysql->query("select * from `news` WHERE id={$vid}");
if($_POST){
    //获取机器人
    $robot = $mysql->query("select `id` from `user` WHERE `isrobot`=1 ORDER BY rand() limit 1");
    $uid = $robot[0]['id'];
    $vid = $_POST['vid'];
    $content = $_POST['title'];
    $pnum = is_numeric($_POST['pnum']) ? $_POST['pnum'] : 1;
    $cnum = is_numeric($_POST['cnum']) ? $_POST['cnum'] : 1;
    $snum = is_numeric($_POST['snum']) ? $_POST['snum'] : 1;
    $res = $mysql->execute("update `news` set `uid`={$uid},`content`='{$content}',`pnum`={$pnum},`cnum`={$cnum},`snum`={$snum},`top`=3 WHERE `id`={$vid}");
    if($res){
        echo "<script>alert('添加成功')</script>";
        echo "<script>location.href='./addVideo.php'</script>";
    }else{
        echo "<script>location.href='./editVideo.php?id={$vid}'</script>";
    }
}
if($_GET['do'] == 'del'){
    $vid = $_GET['vid'];
    $res = $mysql->execute("delete from `news` WHERE `id`={$vid}");
    if($res){
        echo "<script>alert('删除成功')</script>";
        echo "<script>location.href='./addVideo.php'</script>";
    }else{
        echo "<script>location.href='./editVideo.php?id={$vid}'</script>";
    }
}
 ?>
<?php include('head.php') ?>
<script charset="utf-8" src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
<div class="container-fluid">
    <div class="row-fluid">
        <?php
        include('left.php'); ?>
        <div class="span9">
            <h1 class="page-title">发布视频</h1>
            <div class="well">
                <ul class="nav nav-tabs">
                    <li class="active"><a href="#home" data-toggle="tab">发布</a></li>
                    <li class="active">发布成功后到已审核列表查看</li>
                </ul>
                <div id="myTabContent" class="tab-content">
                    <div class="tab-pane active in" id="home">
                        <form id="tab" action="editVideo.php" method="post">
                            <input type="hidden" name="vid" value="<?=$vid?> ">
                            <label>content(视频标题)</label>
                            <input type="text" name="title" style="width:500px" value="<?=$videoInfo[0]['content']?>">
                            <label>URL(视频链接)</label>
                            <input type="text" name="url" style="width:500px" value="<?=$videoInfo[0]['video_url']?> readonly">
                            <label>content(封面图片)</label>
                            <img src="<?=$videoInfo[0]['img']?>">
                            <label>pnum(点赞)</label>
                            <input type="text" name="pnum" style="width:500px">
                            <label>cnum(评论)</label>
                            <input type="text" name="cnum" style="width:500px">
                            <label>snum(赠送)</label>
                            <input type="text" name="snum" style="width:500px">
                            <label>forward</label>
                            <input type="text" name="forward" style="width:500px">
                            <br>
                            <button class="btn btn-primary"><i class="icon-save"></i> 保存</button>
                            <a class="btn btn-primary" href="?do=del&vid=<?=$vid?>">删除</a>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>


</div>
<script>
    $("#img").change(function(){
        var id = $(this).children('option:selected').val();
        $.get("changeImg.php",{uid:id}, function(data){
            console.log(data);
            console.log(data);
            $("#head").attr("src",data.img);
            $("#name").attr("value",data.name);
        },"json")
    });
</script>
<script src="lib/bootstrap/js/bootstrap.js"></script>
</body>
</html>